package com.scuec.groupfive.service.impl;

import com.scuec.groupfive.entity.*;
import com.scuec.groupfive.mapper.RollManagementMapper;
import com.scuec.groupfive.service.RollManagementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class RollManagementServiceImpl implements RollManagementService {

    @Autowired
    private RollManagementMapper rollManagementMapper;

    @Override
    public List<QuestionInfo> getQuestionsByYearAndType(Integer examYear, Integer typeId) {
        return rollManagementMapper.getQuestionsByYearAndType(examYear, typeId);
    }

    @Override
    @Transactional
    public QuestionInfo updateQuestion(QuestionInfo questionInfo) {
        rollManagementMapper.updateQuestion(questionInfo);
        return rollManagementMapper.getQuestionById(questionInfo.getQuestionId());
    }

    @Override
    @Transactional
    public ChoiceQuestion updateChoiceAnswer(ChoiceQuestion choiceQuestion) {
        rollManagementMapper.updateChoiceAnswer(choiceQuestion);
        return rollManagementMapper.getChoiceAnswerByQuestionId(choiceQuestion.getQuestionId());
    }

    @Override
    @Transactional
    public FillBlankQuestion updateFillBlankAnswer(FillBlankQuestion fillBlankQuestion) {
        rollManagementMapper.updateFillBlankAnswer(fillBlankQuestion);
        return rollManagementMapper.getFillBlankAnswerByQuestionId(fillBlankQuestion.getQuestionId());
    }

    @Override
    @Transactional
    public SubjectiveQuestion updateSubjectiveAnswer(SubjectiveQuestion subjectiveQuestion) {
        rollManagementMapper.updateSubjectiveAnswer(subjectiveQuestion);
        return rollManagementMapper.getSubjectiveAnswerByQuestionId(subjectiveQuestion.getQuestionId());
    }
}